home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 302 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: tko.dec.com!diamond
  2. From: diamond@tko.dec.com (Norman Diamond)
  3. Newsgroups: comp.std.c
  4. Subject: Re: size_t
  5. Date: 5 Feb 1996 03:17:14 GMT
  6. Organization: Digital Equipment Corporation Japan , Tokyo
  7. Message-ID: <4f3srq$9ns@usenet.pa.dec.com>
  8. References: <DM48Fv.5Ay@novice.uwaterloo.ca>
  9. Reply-To: diamond@jrdv04.enet.dec-j.co.jp (Norman Diamond)
  10. NNTP-Posting-Host: jit533.tko.dec.com
  11.  
  12. In article <DM48Fv.5Ay@novice.uwaterloo.ca>, lhuang@swen3.uwaterloo.ca (Larry Huang) writes:
  13. >I was writing some code to manage a table the other day. I used
  14. >a size_t to keep track of the size of the table, and I defined a
  15. >macro SIZE_T_MAX as (size_t)(-1) for making sure the table doesn't
  16. >get too large.  Then I suddenly realize that it may not work as
  17. >I thought.  An implementation can restrict the size of a data
  18. >object to 32 K (is my memory correct here?), but the value of
  19. >(size_t)(-1) can at the same time be very large (e.g. ULONG_MAX).
  20.  
  21. True.
  22.  
  23. >So my question is, is there a way to find out what the maximum
  24. >allowable size of a data object  is under an implementation?
  25.  
  26. Statically, I think not.  You can declare one array of 32767 chars and
  27. hope that your program is the lucky one that some implementation will
  28. translate and execute.  If you push any farther then entropy reverses.
  29.  
  30. Dynamically, you can try malloc'ing (size_t)(-1), if it doesn't work
  31. then try (size_t)(-2), etc.  (Notice that a binary search might not
  32. accomplish the actual maximum result, because if the first successful
  33. malloc is 80% of the actual maximum and then you free it, I don't think
  34. the implementation is required to coalesce the free spaces.)
  35. --
  36.  <<  If this were the company's opinion, I would not be allowed to post it.  >>
  37. "I paid money for this car, I pay taxes for vehicle registration and a driver's
  38. license, so I can drive in any lane I want, and no innocent victim gets to call
  39. the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
  40.